/**
 *
 */
package com.angel.io.validators.impl;

import java.lang.reflect.Method;

import com.angel.common.helpers.AnnotationHelper;
import com.angel.common.helpers.ReflectionHelper;
import com.angel.io.annotations.RowProcessor;
import com.angel.io.annotations.RowProcessorCommand;
import com.angel.io.exceptions.RowProcessorCommandValidatorException;
import com.angel.io.validators.RowProcessorCommandValidator;

/**
 * @author William
 *
 */
public class InjectObjectRowProcessorAnnotationValidator implements RowProcessorCommandValidator{

	public void validate(Class<?> importRowCommandClass) throws RowProcessorCommandValidatorException {
		boolean hasAnnotation = AnnotationHelper.hasAnnotation(importRowCommandClass, RowProcessorCommand.class);
		if(hasAnnotation){
			Method rowProcessorMethod = ReflectionHelper.getAllMethodWith(RowProcessor.class, importRowCommandClass)[0];
			RowProcessor rowProcessor = AnnotationHelper.getAnnotation(rowProcessorMethod, RowProcessor.class);
			
			if(Object.class.equals(rowProcessor.object()) && rowProcessor.inject()){
				throw new RowProcessorCommandValidatorException("Cannot inject [" + rowProcessor.inject() + "] attributes automatically in an object class [" + rowProcessor.object() + "].");
			}
		}
	}


}
